package com.jvtd.eyl.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.util.AttributeSet;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jvtd.eyl.R;
import com.jvtd.eyl.bean.binding.PeriodicalBean;
import com.jvtd.eyl.constants.App;
import com.jvtd.eyl.ui.main.home.periodicalInfo.PeriodicalInfoActivity;
import com.jvtd.eyl.widget.adapter.PeriodicalAdapter;
import com.jvtd.widget.emptyView.JvtdEmptyView;
import com.jvtd.widget.recyclerView.JvtdRecyclerView;

/**
 * 期刊列表
 *
 * 作者:chenlei
 * 时间:2018/11/13 4:13 PM
 */
public class PeriodicalRecyclerView extends JvtdRecyclerView<PeriodicalBean> {
    public PeriodicalRecyclerView(@NonNull Context context) {
        super(context);
    }

    public PeriodicalRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PeriodicalRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        PeriodicalAdapter periodicalAdapter = new PeriodicalAdapter();
//        periodicalAdapter.openLoadAnimation();

        periodicalAdapter.setOnItemClickListener((adapter, view, position) -> {
            PeriodicalBean periodicalBean = periodicalAdapter.getItem(position);
            if (periodicalBean != null) {
                mContext.startActivity(PeriodicalInfoActivity.getIntent(mContext, periodicalBean));
            }
        });
        return periodicalAdapter;
    }

    @Override
    public LayoutManager initLayoutManager() {
        return new GridLayoutManager(mContext,4);
    }

    @Override
    public boolean isFirst() {
        return false;
    }

    @Override
    public int getLoadNum() {
        return 0;
    }

    @Override
    protected void configEmptyView(JvtdEmptyView emptyView) {
        emptyView.setEmptyImage(0)
                .setErrorText(R.string.loading_failed_touch)
                .setErrorImage(0)
                .setLoadingText("")
                .setEmptyText(R.string.empty_book_tips);
    }

    @Override
    public double getFlingRatio()
    {
        return App.FLING_RATIO;
    }
}
